package xyz.fuqufyb.aec.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.fuqufyb.aec.dao.AppInfoMapper;
import xyz.fuqufyb.aec.data.TableResult;
import xyz.fuqufyb.aec.entity.AppInfo;
import xyz.fuqufyb.aec.service.IAppInfoService;

import java.util.List;
import java.util.Map;

/**
 * @author 用户: fyb
 * @description class: AppInfoServiceImpl
 * @date 时间: 2021/2/2 10:43
 */
@Service("IAppInfoService")
public class AppInfoServiceImpl implements IAppInfoService {

    @Autowired
    private AppInfoMapper appInfoMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        int i = appInfoMapper.deleteByPrimaryKey(id);

        if (i > 0) {

            return i;
        }

        return 0;

    }

    @Override
    public int insert(AppInfo record) {

        int insert = appInfoMapper.insert(record);
        if (insert > 0) {

            return insert;
        }
        return 0;
    }

    @Override
    public int insertSelective(AppInfo record) {
        int i = appInfoMapper.insertSelective(record);
        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public AppInfo selectByPrimaryKey(Integer id) {
        AppInfo appInfo = appInfoMapper.selectByPrimaryKey(id);
        if (appInfo != null) {
            return appInfo;
        }
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(AppInfo record) {
        int i = appInfoMapper.updateByPrimaryKeySelective(record);
        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public int updateByPrimaryKey(AppInfo record) {
        int i = appInfoMapper.updateByPrimaryKey(record);
        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public TableResult getPageAppInfo(Map<String,Object> maps) {

        String page = (String) maps.get("page");
        String limit = (String) maps.get("limit");
        if (page != null && limit != null) {
            PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));

            List<AppInfo> appInfos = appInfoMapper.getPageAppInfo(maps);
            PageInfo<AppInfo> pageInfo = new PageInfo<>(appInfos);

            return TableResult.getTableResultSuccess(pageInfo.getTotal(), pageInfo.getList());
        }

        return TableResult.getTableResultError("参数不能为空");
    }

    @Override
    public int deleteByAppInfoIds(List<Integer> asList) {

        int i = appInfoMapper.deleteByAppInfoIds(asList);
        if (i > 0) {
            return i;
        }
        return 0;
    }
}




